home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / modem / modem-account.frm.z / modem-account.frm
Encoding:
Text File  |  1997-07-30  |  10.9 KB  |  389 lines

  1. #!/usr/bin/perl5
  2. #
  3. # modem-accounts.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: modem-account.frm,v 1.40 1997/06/19 22:25:59 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/uucp/Systems";
  26. $dummy = "/etc/uucp/Systems.temp";
  27. $myname = "modem-account.cgi";
  28. $title = "Modem Accounts";
  29.  
  30. $js_main = "
  31. type = \"account\";
  32. $js_account_main
  33. $js_error_box
  34. $js_meta
  35. function testAdd(form) {
  36.     if (!testMeta(form.nme, \"account name\")) return (false);
  37.     return (true);
  38. }";
  39.  
  40. $js_add =
  41. "$js_account_add
  42. $js_error_box
  43. $js_phone
  44. $js_meta
  45. function testAdd(form) {
  46.     if (!testPhone(form.phone)) return (false);
  47.     if (!testMeta(form.login,\"login name\")) return (false);
  48.     if (!testMeta(form.password,\"login password\")) return (false);
  49.     return (true);
  50. }";
  51.  
  52.  
  53. $js_edit = 
  54. "$js_account_edit
  55. $js_error_box
  56. $js_phone
  57. $js_meta
  58. function testEdit(form) {
  59.     if (!testMeta(form.nme,\"remote host name\")) return (false);
  60.     if (!testPhone(form.phone)) return (false);
  61.     if (!testMeta(form.login,\"login name\")) return (false);
  62.     if (!testMeta(form.password,\"password\")) return (false);
  63.     return (true);
  64. }";
  65.  
  66. print "Content-type: text/html\n\n";
  67.  
  68. &get_fields;
  69.  
  70. &getAccounts;
  71.  
  72. if (%fld) {
  73.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  74.     $help =~ s/cgi$/hlp/;
  75.     exec $help if ($fld{'help'} eq "Help");
  76.  
  77.     $fld{'phone'} =~ s/-//g;
  78.     $fld{'phone'} =~ s/\(//g;
  79.     $fld{'phone'} =~ s/\)//g;
  80.     $fld{'phone'} =~ s/,//g;
  81.     $fld{'chosen'} =~ /([\w.-]+)/;
  82.     $fld{'chosen'} = $1;
  83. }
  84.  
  85. if ($fld{'add'}) { 
  86.     &formValid_add;
  87.     $val{'nme'} = $fld{'nme'}; 
  88.     &addAccount; 
  89. }
  90. elsif ($fld{'delete'}) { 
  91.     &error(2,"To delete an existing account, first select an account from
  92.     list, then click the delete button.") if !$fld{'chosen'};
  93.     $message = qq|Click "Ok" to save changes.|; 
  94.     &generic($fld{'chosen'}); 
  95. }
  96. elsif ($fld{'edit'}) { 
  97.     &error(2,"To edit an existing account, first select an account from
  98.     list, then click the edit button.") if !$fld{'chosen'};
  99.     &putEdit; 
  100.     &editAccount; 
  101. }
  102. elsif ($fld{'doedit'}) { &formValid_doedit; &doEdit; &getAccounts; &generic; }
  103. elsif ($fld{'doit'}) {
  104.     &tryToDelete; 
  105.     &getAccounts; 
  106.     if (!$message) { $message = "No changes made."; }
  107.     &generic; 
  108. }
  109. elsif ($fld{'doadd'}) { &formValid_doadd; &doAdd; &getAccounts; &generic; }
  110. else {
  111.     if (%fld) { $val{'nme'} = $fld{'nme'}; $message = qq|Use buttons to submit form.|; } 
  112.     &generic; 
  113. }
  114.  
  115. sub formValid_add {
  116.     &error(2,"Account name required.") if !$fld{'nme'};
  117.     &error(2,"Invalid account name.") if &deluxeError($fld{'nme'});
  118. }
  119.  
  120. sub formValid_doadd {
  121.     &error(0,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
  122.     &error(0,"Invalid login name.") if &deluxeError($fld{'login'});
  123.     &error(0,"Invalid password.") if &deluxeError($fld{'password'});
  124. }
  125.  
  126.  
  127. sub formValid_doedit {
  128.     &error(1,"Invalid remote host name.") if &deluxeError($fld{'nme'});
  129.     &error(1,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
  130.     &error(1,"Invalid login name.") if &deluxeError($fld{'login'});
  131.     &error(1,"Invalid password.") if &deluxeError($fld{'password'});
  132. }
  133.  
  134. sub deluxeError {
  135.     return 1 if length($_[0]) > 8;
  136.     return 1 if $_[0] =~ /$METACHARS/o;
  137.     return 1 if $_[0] =~ /\s/;
  138.     0;
  139. }
  140.  
  141. sub error {
  142.     &error_block($_[1]);
  143.     %val = %fld;
  144.     if ($_[0] == 0) { &addAccount; }
  145.     elsif ($_[0] == 1) { &editAccount; }
  146.     else { &generic; }
  147.     exit 0;
  148. }
  149.  
  150. sub doEdit {
  151.     open(IN,"< $conf");
  152.     open(OUT,"> $dummy");
  153.     $found = 0;
  154.     while(<IN>) {
  155.     $line = $_;
  156.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  157.     $line =~ /^\s*(.*)$/;
  158.     $line1 = $1;
  159.     @items = split(/\s+/,$line1);
  160.     if ($items[2] eq "ACU" && $items[0] eq $fld{'chosen'}) {
  161.         print OUT "# $line";
  162.         if ($found == 0) {
  163.         $found = 1;
  164.         print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
  165.         print OUT " in:--in: $fld{'login'}";
  166.         if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  167.         print OUT "\n";
  168.         }
  169.     } else { print OUT $line; }
  170.     }
  171.     if ($found == 0) {
  172.     print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
  173.     print OUT " in:--in: $fld{'login'}";
  174.     if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  175.     print OUT "\n";
  176.     }
  177.     close(IN);
  178.     close(OUT);    
  179.     chmod 0600, $conf;
  180.     rename($dummy,$conf);
  181.     chmod 0400, $conf;
  182.  
  183.     $message = "Account edited.";
  184. }    
  185.  
  186. sub clear {
  187.     open(OUT_0,"> $_[0]");
  188.     close(OUT_0);
  189. }
  190.  
  191. sub putEdit {
  192.     $num = -1;
  193.     for ($i=0;$i<$number;$i++) {
  194.     if ($nme[$i] eq $fld{'chosen'}) { $num = $i; }
  195.     }
  196.  
  197.     $val{'nme'} = $nme[$num];
  198.     $val{'phone'} = $phone[$num];
  199.     $val{'login'} = $login[$num];
  200.     $val{'password'} = $password[$num];
  201.     $val{'speed'} = $speed[$num];
  202. }
  203.  
  204. sub editAccount {
  205.     &js_title_block($title, $js_edit);
  206.     &header_block("Edit Modem Account");
  207.  
  208.     print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  209.  
  210.     print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|;
  211.  
  212.     print "<center><table cellpadding=5 width=450>";
  213.  
  214.     print "<tr><th align=left>Remote host name:</th><th align=left>",
  215.       &text('nme',$val{'nme'}, 20),"</th></tr>";
  216.  
  217.     print "<tr><th align=left>Phone number:</th><th align=left>",
  218.       &text('phone',$val{'phone'}, 20),"</th></tr>";
  219.  
  220.     print "<tr><th align=left>Login name:</th><th align=left>",
  221.       &text('login',$val{'login'}, 20),"</th></tr>";
  222.  
  223.     print "<tr><th align=left>Password:</th><th align=left>",
  224.       &text('password',"$val{'password'}", 20),"</th></tr>";   
  225.  
  226.     print "<tr><th align=left>Baud rate:</th><th align=left>",
  227.       &select('speed',$val{'speed'},
  228.       '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
  229.  
  230.     print "</table></center><br>";
  231.  
  232.     print &js_buttons('doedit','Ok','onClick="markEdit()"','onClick="markOther()"');
  233.  
  234.     print "</form></body></html>";
  235. }
  236.     
  237. sub tryToDelete {
  238.     $account = $fld{'toDelete'};
  239.     if (!$account) { return 0; }
  240.  
  241.     open(IN,"< $conf");
  242.     open(OUT,"> $dummy");
  243.     while(<IN>) {
  244.     $line = $_;
  245.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  246.     $line =~ /^\s*(.*)$/;
  247.     $line1 = $1;
  248.     @items = split(/\s+/,$line1);
  249.     if ($items[2] eq "ACU" && $items[0] eq $account) {
  250.         print OUT "# $line";
  251.     } else { print OUT $line; }
  252.     }
  253.     close(IN);
  254.     close(OUT);
  255.     chmod 0600, $conf;
  256.     rename($dummy,$conf);
  257.     chmod 0400, $conf;
  258.  
  259.     $message = "Account deleted.";    
  260. }
  261.  
  262. sub doAdd {
  263.     chmod 0600, $conf;
  264.     open(OUT,">> $conf");
  265.     print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'} in:--in:";
  266.     print OUT " $fld{'login'}";
  267.     if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  268.     print OUT "\n";
  269.     close(OUT);
  270.     chmod 0400, $conf;
  271.  
  272.     $message = "New account added.";
  273. }
  274.  
  275. sub addAccount {
  276.     &js_title_block($title, $js_add);
  277.     &header_block("Add New Modem Account");
  278.  
  279.     print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  280.  
  281.     print "<center><table cellpadding=5 width=450>\n";
  282.  
  283.     print "<input type=hidden name=nme value=$val{'nme'}>\n";
  284.  
  285.     print "<tr><th align=left>Remote host name:</th><td><tt>",
  286.       $val{'nme'},"</tt></td></tr>\n";
  287.  
  288.     print "<tr><th align=left>Phone number:</th><th align=left>",
  289.       &text('phone',"$val{'phone'}",20),"</th></tr>\n";
  290.  
  291.     print "<tr><th align=left>Login name:</th><th align=left>",
  292.       &text('login',"$val{'login'}",20),"</th></tr>\n";
  293.  
  294.     print "<tr><th align=left>Password:</th><th align=left>",
  295.       &text('password',"$val{'password'}",20),"</th></tr>\n";
  296.  
  297.     print "<tr><th align=left>Baud rate:</th><th align=left>",
  298.       &select('speed',$val{'speed'},
  299.       '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
  300.  
  301.     print "</table></center><br>";
  302.  
  303.     print &js_buttons('doadd','Ok','onClick="markAdd()"','onClick="markOther()"');
  304.  
  305.     print "</form></body></html>";
  306. }
  307.  
  308. sub getAccounts {
  309.     $i = 0;
  310.     open(IN,"< $conf");
  311.     while(<IN>) {
  312.     $line = $_;
  313.     if ($line =~ /^\s*\#/) { next; }
  314.     $line =~ /^\s*(.*)$/;
  315.     $line1 = $1;
  316.     @items = split(/\s+/,$line1);
  317.     if ($items[2] eq "ACU") {
  318.         $nme[$i] = $items[0];
  319.         $speed[$i] = $items[3];
  320.         $phone[$i] = $items[4];
  321.         for ($j=5;$j<$#items;$j++) {
  322.         if (substr($items[$j],length($items[$j])-3,3) eq 'in:') 
  323.             { $login[$i] = $items[$j+1]; }
  324.         if (substr($items[$j],length($items[$j])-3,3) eq 'rd:') 
  325.             { $password[$i] = $items[$j+1]; }
  326.         }
  327.         $i++;
  328.     }
  329.     }
  330.     $number = $i;
  331.     close(IN);
  332. }
  333.     
  334.  
  335. sub generic {
  336.     &js_title_block($title, $js_main);
  337.     &header_block($title);
  338.  
  339.     if (!$number && !$message) { $message = "No existing modem accounts."; }
  340.     print "<i>$message</i>";
  341.  
  342.     print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  343.  
  344.     if($_[0]) { print "<input type=hidden name=toDelete value=$_[0]>\n"; }
  345.  
  346.     if ($number) {
  347.         print "<h3>List of modem accounts:</h3><center>";
  348.  
  349.         print "<table cellpadding=5 width=450>\n";
  350.  
  351.         print qq|<tr><th align=left><input type=submit name="add" 
  352.         value="Add New Account" onClick="markAdd()">
  353.         </th><td align=left><input name="nme" value="$val{'nme'}" size=19>
  354.         </td></tr>|; 
  355.  
  356.         print "<tr><th align=left>";
  357.         print qq|<input type=submit name="edit" 
  358.         value="Edit Selected Account" onClick="markEdit()"></th>
  359.         |;
  360.  
  361.         print "<td rowspan=2 align=left>";
  362.         undef @locList;
  363.         for ($i=0;$i<$number;$i++) { 
  364.             if ($nme[$i] ne $_[0]) { push(@locList,$nme[$i]); } 
  365.         }
  366.         print &choice_list(*locList,"chosen",20);
  367.  
  368.         print "</td></tr>";
  369.  
  370.         print qq|<tr><th align=left><input type=submit name="delete" 
  371.         value="Delete Selected Account" onClick="markDelete()">
  372.         </th></tr>|;    
  373.  
  374.         print "</table></center><br>\n";
  375.  
  376.     } else {
  377.         print "<center><table cellpadding=5 width=450>\n";
  378.         print qq|<tr><th align=left><input type=submit name="add" 
  379.         value="Add New Account" onClick="markAdd()"> </th><td align=left>        
  380.         <input name="nme" value="$val{'nme'}" size=19> </td></tr>|; 
  381.         print "</table></center><br>";
  382.     }
  383.  
  384.     print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
  385.  
  386.     print "</form></body></html>";
  387. }
  388.  
  389.